package com.xbongbong.pro.enums.raiders.enums;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 价值攻略解锁枚举
 * @author zcp
 * @version v1.0
 * @date 19/9/18 018 20:36
 * @update 19/9/18 018 20:36
 * @since v1.0
 */
@Getter
public enum RaidersLockEnum {
    /**
     * 解锁枚举，对应数据库内lock字段
     */
    UN_LOCK(1, "enum.raidersLock.name.un_lock", "enum.raidersLock.status.un_lock"),

    FINISH_PRE_STEP(2, "enum.raidersLock.name.finish_pre_step", "enum.raidersLock.status.finish_pre_step"),

    UNKNOWN(404, "enum.raidersLock.name.unknown", "enum.raidersLock.status.unknown"),

    ;

    /**
     * 枚举值 --
     */
    private final int code;
    /**
     * 枚举信息--中文名称
     */
    private final String name;
    /**
     * 枚举信息--状态
     */
    private final String status;

    RaidersLockEnum(int code, String name, String status) {
        this.code = code;
        this.name = name;
        this.status = status;
    }

    /**
     * 通过code获取枚举
     * @param code
     * @return com.xbongbong.pro.enums.raiders.enums.RaidersLockEnum
     * @author zcp
     * @date 19/9/19 019 14:01
     * @update 19/9/19 019 14:01
     * @since v1.0
     * @version v1.0
     */
    public static RaidersLockEnum getByCode(int code){
        for (RaidersLockEnum cache : values()) {
            if (Objects.equals(cache.code, code)) {
                return cache;
            }
        }
        //默认无需解锁
        return UN_LOCK;
    }

    /**
     * 格式化下拉选项
     * @return com.alibaba.fastjson.JSONArray
     * @author zcp
     * @date 19/9/21 021 14:29
     * @update 19/9/21 021 14:29
     * @since v1.0
     * @version v1.0
     */
    public static JSONArray formatOption() {
        JSONArray jsonArray = new JSONArray();
        for (RaidersLockEnum cache : values()) {
            if (Objects.equals(cache, UNKNOWN)) {
                continue;
            }
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("key", cache.getCode());
            jsonObject.put("value", cache.getName());
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getStatus() {
        return I18nMessageUtil.getMessage(status);
    }
}
